package com.zima.mall.controller;

import com.zima.mall.entity.Address;
import com.zima.mall.entity.MallUser;
import com.zima.mall.service.UserService;
import com.zima.mall.vo.BuyVo;
import com.zima.mall.vo.TableVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/getUsername/{account}")
    public String getUsername(@PathVariable("account") String account){
        return userService.findByAccount(account);
    }

    @RequestMapping("/findAllAverageUsers/{page}/{size}")
    public TableVo findAllAverageUsers(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        return userService.findAllAverageUsers(page,size);
    }

    @RequestMapping("/consumptionStatics/{id}")
    public float consumptionStatics(@PathVariable Integer id){
        return userService.consumptionStatics(id);
    }

    @RequestMapping("/findAddressByAccount/{account}")
    public TableVo findAddressByAccount(@PathVariable String account){
        return userService.findAddressByAccount(account);
    }

    @RequestMapping("/order")
    public Integer order(@RequestBody BuyVo buyVo){
        return userService.order(buyVo);
    }

    @RequestMapping("/register")
    public Integer register(@RequestBody MallUser mallUser){
        return userService.register(mallUser);
    }

    @RequestMapping("/getUserInfo/{account}")
    public TableVo getUserInfo(@PathVariable String account){
        return userService.getUserInfo(account);
    }

    @RequestMapping("/editUser")
    public Integer editUser(@RequestBody MallUser mallUser){
        return userService.editUser(mallUser);
    }

    @RequestMapping("/delAddress/{id}")
    public Integer delAddress(@PathVariable Integer id){
        return userService.delAddress(id);
    }

    @RequestMapping("/addAddress/{account}")
    public Integer addAddress(@RequestBody Address address,@PathVariable String account){
        return userService.addAddress(address,account);
    }

    @RequestMapping("/editAddress")
    public Integer editAddress(@RequestBody Address address){
        return userService.editAddress(address);
    }

}
